﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusStation
{
    class TimeInterval
    {
        private TimeSpan arriveTime;
        private TimeSpan leaveTime;

        public TimeSpan ArriveTime
        {
            get { return arriveTime; }
        }
        public TimeSpan LeaveTime
        {
            get { return leaveTime; }
        }

        public TimeInterval(TimeSpan arriveTime, TimeSpan leaveTime)
        {
            this.arriveTime = arriveTime;
            this.leaveTime = leaveTime;
        }
        public TimeInterval(string stringTime)
        {
            StringBuilder stringBuilder = new StringBuilder(stringTime.Length * 2);
            foreach (char item in stringTime)
            {
                if (char.IsDigit(item))
                {
                    stringBuilder.Append(item);
                }
                else
                {
                    stringBuilder.Append(' ');
                }
            }

            string[] stringTimes = stringBuilder.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            this.arriveTime = new TimeSpan(int.Parse(stringTimes[0]), int.Parse(stringTimes[1]), 0);
            this.leaveTime = new TimeSpan(int.Parse(stringTimes[2]), int.Parse(stringTimes[3]), 0);
        }

        //public override int GetHashCode()
        //{
        //    return arriveTime.GetHashCode() ^ leaveTime.GetHashCode();
        //}
        //public override bool Equals(object obj)
        //{
        //    if (obj.GetType() != typeof(TimeInterval))
        //        return false;

        //    TimeInterval p = (TimeInterval)obj;
        //    return ((this.arriveTime == p.arriveTime) && (this.leaveTime == p.leaveTime));
        //}
    }
}
